package com.qfoud.edu.aunt.commons.dao.impl;

import com.qfoud.edu.aunt.commons.dao.IMenuDAO;
import com.qfoud.edu.aunt.commons.pojo.Menu;
import com.qfoud.edu.aunt.commons.utils.JdbcUtils;
import com.qfoud.edu.dbutils.framwork.result.impl.BeanListHandler;

import java.util.List;

/**
 * @author xiaobobo
 * @title: MenuDAO
 * @projectName cd-java-2303-project-parent
 * @description: 菜单的DAO的实现
 * @date 2023/5/16  10:33
 */
public class MenuDAO implements IMenuDAO {
    @Override
    public List<Menu> findPermsByUserId(Integer userId) throws Exception {
        return JdbcUtils.queryRunner().query(
               "SELECT t4.*\n" +
                       "\n" +
                       "FROM t_user_role t1\n" +
                       "\n" +
                       "JOIN t_role t2 ON t1.roleId=t2.roleId\n" +
                       "\n" +
                       "JOIN t_role_menu t3 ON t2.roleId=t3.roleId\n" +
                       "\n" +
                       "JOIN t_menu t4 ON t3.permId=t4.permId\n" +
                       "\n" +
                       "WHERE t1.userId=? AND t4.typeLevel=2",new BeanListHandler<Menu>(Menu.class),userId
        );
    }
}
